package queue;

import array.CandyArray;
/**
 * 
 * @Title: CandyArrayQueue.java 
 * @Package queue 
 * @Description: 自定义一个队列
 * @author CandyWall   
 * @date 2020年12月19日 上午11:01:20 
 * @version V1.0
 */
public class CandyArrayQueue<E> implements CandyQueue<E> {
	private CandyArray<E> candyArray;

	public CandyArrayQueue() {
		candyArray = new CandyArray<>();
	}

	public CandyArrayQueue(int capacity) {
		candyArray = new CandyArray<>(capacity);
	}
	
	@Override
	public int getSize() {
		return candyArray.getSize();
	}

	@Override
	public boolean isEmpty() {
		return candyArray.isEmpty();
	}

	@Override
	public void enqueue(E e) {
		candyArray.addLast(e);
	}

	@Override
	public E dequeue() {
		return candyArray.removeFirst();
	}

	@Override
	public E getFront() {
		return candyArray.getFirst();
	}
	
	@Override
	public int getCapacity() {
		return candyArray.getCapacity();
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder("CandyArrayQueue: front [");
		for(int i = 0; ; i++) {
			sb.append(candyArray.get(i));
			if(i == candyArray.getSize() - 1)
				return sb.append("] rear").toString();
			sb.append(", ");
		}
	}

	public static void main(String[] args) {
		CandyArrayQueue<Integer> queue = new CandyArrayQueue<>();
		for(int i = 0; i < 10; i++) {
			queue.enqueue(i);
			System.out.println(queue);
		}
		System.out.println(queue.dequeue());
		System.out.println(queue);
	}
}
